#include "rsp_put.hpp"
#include "../action_constants.hpp"

namespace etcdv3 {

void AsyncPutResponse::ParseResponse(PutResponse& resp, bool prefix) {
    index = resp.header().revision();

    if (resp.has_prev_kv() == false) {
        error_code = 100;
        error_message = "Key not found";
        return;
    } else {
        action = PUT_ACTION;
        KeyValue kv;
        kv.kvs.CopyFrom(resp.prev_kv());
        values.push_back(kv);

        if (!prefix && values.empty() == false) {
            prev_value = values[0];
            value = values[0];
            value.kvs.clear_value();
            values.clear();
        }
    }
}

}
